package net.zjitc.controller;

import net.zjitc.common.ResultMessage;
import net.zjitc.pojo.Category;
import net.zjitc.pojo.Notice;
import net.zjitc.pojo.Product;
import net.zjitc.service.CategoryService;
import net.zjitc.service.NoticeService;
import net.zjitc.service.ProductService;
import net.zjitc.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @AUTHOR zhj
 * @DATE 2019/4/8 15:59
 */
@Controller
public class IndexController {
    final String SALE_DAY_SEVEN = "7";
    final int NOTICE_NUM = 1;
    @Autowired
    CategoryService categoryService;
    @Autowired
    ProductService productService;
    @Autowired
    NoticeService noticeService;
    @Autowired
    SaleService saleService;


    @RequestMapping("/index")
    public String index(Model model){
        //saleService.f
        //商品应该按销量来
        List<Product> productList =saleService.countHotSaleProducts(SALE_DAY_SEVEN);
        //只查最新的公告
        Notice notice= noticeService.findLastNotice(NOTICE_NUM);
        model.addAttribute("plist",productList);
        model.addAttribute("notice",notice);
        return "/client/index.jsp";
    }

    @RequestMapping("/category")
    @ResponseBody
    public List<Category> getCagegory(){
        List<Category> list = categoryService.findAllCategory();
        return list;
    }
}
